/*****************************************************************************
	File Name:			Player.cpp
	Authors:			Marc Willis, Trey Turley, Thomas Lee
	Description:		Defines functions for the Player class
	Date Modified:		08/07/2010
						-Modifed to contain a pointer to the GameMap the
						 player will be on, added advance function
						08/01/2010
						-File Created
*****************************************************************************/

#include "Player.h"

/*****************************************************************************
	Function Name:		Player()
	Description:		Default constructor for the Player class, creates a
						Player with default stats
	Input:
		(none)
	Output:
		(none)
*****************************************************************************/
Player::Player()
{
	x=0;
	y=0;
	color=1;
	dir=DIR_LEFT;
	gm=NULL;
	alive=true;
}
/*****************************************************************************
	Function Name:		Player(int,int,int,int)
	Description:		Constructor for the Player class, creates a Player
						with the given stats
	Input:
		int x			x of the player
		int y			y of the player
		int dir			direction of the player
		int color		color of the player
		GameMap &g		GameMap to be referenced
	Output:
		(none)
*****************************************************************************/
Player::Player(int x,int y,int dir,int color,GameMap &g)
{
	this->x=x;
	this->y=y;
	this->dir=dir;
	this->color=color;
	this->gm=&g;
	alive=true;
}
/*****************************************************************************
	Function Name:		getColor()
	Description:		Gets the color of the player  
	Input:
		(none)
	Output:
		int				the player's color
*****************************************************************************/
int Player::getColor()
{
	return color;
}
/*****************************************************************************
	Function Name:		getDir()
	Description:		Gets the direction of the player  
	Input:
		(none)
	Output:
		int				the player's direction
*****************************************************************************/
int Player::getDir()
{
	return dir;
}
/*****************************************************************************
	Function Name:		getX()
	Description:		Gets the x coordinate of the player  
	Input:
		(none)
	Output:
		int				the player's x
*****************************************************************************/
int Player::getX()
{
	return x;
}
/*****************************************************************************
	Function Name:		getY()
	Description:		Gets the y coordinate of the player  
	Input:
		(none)
	Output:
		int				the player's y
*****************************************************************************/
int Player::getY()
{
	return y;
}
/*****************************************************************************
	Function Name:		setX(int)
	Description:		Sets the x coordinate of the player  
	Input:
		int n			the player's new x
	Output:
		(none)
*****************************************************************************/
void Player::setX(int n)
{
	x=n;
}
/*****************************************************************************
	Function Name:		setY(int)
	Description:		Sets the y coordinate of the player  
	Input:
		int n			the player's new y
	Output:
		(none)
*****************************************************************************/
void Player::setY(int n)
{
	y=n;
}

/*****************************************************************************
	Function Name:		advance()
	Description:		Advances the player in the map.
	Input:
		(none)
	Output:
		(none)
*****************************************************************************/
void Player::advance()
{	
	if(dir==DIR_UP)
	{
		gm->markBlock(x,y,color-8,UP);
	}
	if(dir==DIR_DOWN)
	{
		gm->markBlock(x,y,color-8,DOWN);
	}
	if(dir==DIR_LEFT)
	{
		gm->markBlock(x,y,color-8,LEFT);
	}
	if(dir==DIR_RIGHT)
	{
		gm->markBlock(x,y,color-8,RIGHT);
	}

	refreshDir();

	if(dir==DIR_UP)
	{
		y--;
		if(!gm->isSafe(x,y))
		{
			alive=false;
			gm->markBlock(x,y,color,DEAD);
		}else{
			gm->markBlock(x,y,color,UP);
		}
	}
	if(dir==DIR_DOWN)
	{
		y++;
		if(!gm->isSafe(x,y))
		{
			alive=false;
			gm->markBlock(x,y,color,DEAD);
		}else{
			gm->markBlock(x,y,color,DOWN);
		}
	}
	if(dir==DIR_LEFT)
	{
		x--;
		if(!gm->isSafe(x,y))
		{
			alive=false;
			gm->markBlock(x,y,color,DEAD);
		}else{
			gm->markBlock(x,y,color,LEFT);
		}
	}
	if(dir==DIR_RIGHT)
	{
		x++;
		if(!gm->isSafe(x,y))
		{
			alive=false;
			gm->markBlock(x,y,color,DEAD);
		}else{
			gm->markBlock(x,y,color,RIGHT);
		}
	}
}

/*****************************************************************************
	Function Name:		isAlive()
	Description:		Gets alive value for the player
	Input:
		(none)
	Output:
		bool			the player's alive status
*****************************************************************************/
bool Player::isAlive()
{
	return alive;
}

/*****************************************************************************
	Function Name:		setAlive(bool)
	Description:		sets alive value for the player
	Input:
		bool a			the player's alive status	
	Output:
		(none)
*****************************************************************************/
void Player::setAlive(bool a)
{
	alive=a;
}
